home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / basic / qbser15.zip / PCBDOOR.BAS < prev    next >
BASIC Source File  |  1989-06-08  |  6KB  |  195 lines

  1.     DECLARE SUB OpenComm CDECL ALIAS "_open_comm" (BYVAL Port%, BYVAL Wlen%, BYVAL Parity%, BYVAL Baud&, BYVAL HS%)
  2.     DECLARE SUB CloseComm CDECL ALIAS "_close_comm" ()
  3.     DECLARE FUNCTION WriteChar% CDECL (BYVAL Ascii%)
  4.     DECLARE FUNCTION ReadChar% CDECL ()
  5.     DECLARE SUB Transmit CDECL ALIAS "_transmit_string" (addr$)
  6.     DECLARE FUNCTION DataWaiting% CDECL ALIAS "_data_waiting" ()
  7.     DECLARE SUB ClearInputBuffer CDECL ALIAS "_clear_input_buffer" ()
  8.  
  9.     DEFINT A-Z
  10.  
  11.     CRLF$ = CHR$(13) + CHR$(10)
  12.  
  13. '   Pick up name of config file with COMMAND$, then open and parse the file
  14. '   extracting what you need. You'll recognize the parameters. Substitute
  15. '   new names for parameters you door needs. Some of these (perhaps all?)
  16. '   you can leave intact and use.
  17.     
  18.     IF FileExists(COMMAND$ + CHR$(0)) THEN
  19.         OPEN COMMAND$ FOR INPUT ACCESS READ SHARED AS #1
  20.         WHILE NOT EOF(1)
  21.             LINE INPUT #1, A$
  22.             A$ = UCASE$(A$)
  23.             IF INSTR(A$, "FILES=") THEN
  24.                 X = INSTR(A$, "=")
  25.                 Files$ = MID$(A$, X + 1)
  26.             ELSEIF INSTR(A$, "INTRO=") THEN
  27.                 X = INSTR(A$, "=")
  28.                 Intro$ = MID$(A$, X + 1)
  29.             ELSEIF INSTR(A$, "CARRIER=") THEN
  30.                 X = INSTR(A$, "=")
  31.                 CarrierDetect$ = MID$(A$, X + 1)
  32.             ELSEIF INSTR(A$, "HANDSHAKE=") THEN
  33.                 X = INSTR(A$, "=")
  34.                 Handshake$ = MID$(A$, X + 1)
  35.             END IF
  36.         WEND
  37.         CLOSE #1
  38.     ELSE
  39.         PRINT "SYSOP: Configuration file cannot be found. Program returning"
  40.         END
  41.     END IF
  42.  
  43.     PCBoardDat$ = "PCBoard.Dat"
  44.     PCBoardSys$ = "PCBoard.Sys"
  45.  
  46.     IF FileNotFound(PCBoardSys$ + CHR$(0)) THEN
  47.         PRINT "SYSOP: Cannot find PCBoard.Sys, are you in the right DIR?"
  48.         END
  49.     END IF
  50.     IF FileNotFound(PCBoardDat$ + CHR$(0)) THEN
  51.         PRINT "SYSOP: Cannot find PCBoard.Dat, are you in the right DIR?"
  52.         END
  53.     END IF
  54.  
  55.     SELECT CASE Handshake$      ' Set the proper Handshake
  56.         CASE "XON"
  57.             HS = 1
  58.         CASE "CTS"
  59.             HS = 2
  60.         CASE "BOTH"
  61.             HS = 3
  62.         CASE ELSE
  63.             HS = 0
  64.     END SELECT
  65.  
  66. '   Extract parameters from PBOARDS.SYS & PCBOARD.DAT
  67. '   Callers$ = Location of the callers log (with node number tacked on)
  68. '   Port = The comm port number
  69. '   CurrentBaud$ = The current baud rate or LOCAL
  70. '   Node = Current Node (if used)
  71.  
  72.     OPEN PCBoardSys$ FOR RANDOM ACCESS READ SHARED AS #7 LEN = 128
  73.     FIELD #7, 128 AS Board$
  74.     GET #7, 1
  75.     OPEN PCBoardDat$ FOR INPUT AS #1
  76.     LINE INPUT #1, A$
  77.     FOR Lp = 1 TO 28
  78.         INPUT #1, A$
  79.     NEXT Lp
  80.     INPUT #1, Callers$
  81.     CLOSE #1
  82.     Node = ASC(MID$(Board$, 112, 1))
  83.     IF Node THEN
  84.         Callers$ = Callers$ + MID$(STR$(Node), 2)
  85.     END IF
  86.     CurrentBaud$ = LTRIM$(RTRIM$(UCASE$(MID$(Board$, 19, 5))))
  87.     Port = VAL(MID$(Board$, 126, 1))
  88.  
  89. '   Comm port initilization call format:
  90.  
  91. '   OpenComm Port%, Wordlen%, Parity%, Baudrate&, Handshake%
  92.  
  93. '   NOTICE: The Baudrate, Parity & Wordlength ARE NOT CHANGED!! (Passed as 0)
  94. '   WHY? Because why change them when they are already set the way you
  95. '   want them.
  96.  
  97.     IF CurrentBaud$ = "LOCAL" THEN
  98.         OpenComm 0, 0, 0, 0, 0          'This NEEDS to be here like this
  99.                                         'so calls to Transmit will return
  100.                                         'properly when in local. No data is
  101.                                         'transmitted when in this condition
  102.     ELSE
  103.         OpenComm Port, 0, 0, 0, HS
  104.     END IF
  105.          
  106. '   Enable Carrier Detect trap ONLY if NOT in Local and NOT disabled by the  
  107. '   Sysop
  108.  
  109.     IF CarrierDetect$ <> "NO" AND MID$(CurrentBaud$, 1, 4) <> "LOCA" THEN
  110.         ON UEVENT GOSUB SysopClose
  111.         UEVENT ON
  112.     END IF
  113.  
  114. '***************************************************************************
  115. '   Your CODE goes here. Heres an example:
  116.  
  117.     ' To send data out
  118.  
  119.     Temp$ = "This is transmitted out the serial port." + CRLF$
  120.     Transmit Temp$
  121.  
  122.     'To get data from remote (or local) keyboard.
  123.  
  124.     Temp$ = "Enter data: "
  125.     PRINT Temp$
  126.     Transmit Temp$
  127.     Transmit CRLF$
  128.     GOSUB KeyboardInput
  129.     Temp$ = "You entered: " + A$
  130.     PRINT Temp$
  131.     Transmit Temp$
  132.     Transmit CRLF$
  133.  
  134. '   Your code ends here
  135. '****************************************************************************
  136.  
  137.     'VERY important ending step - if you forget this, you CRASH sometime later.
  138.     'But ONLY restore the vectors if you actually took them, otherwise
  139.     'you'll cause a crash for other reasons.
  140.  
  141. RestoreInt:
  142.  
  143.     IF MID$(CurrentBaud$, 1, 4) <> "LOCA" THEN
  144.         CloseComm
  145.     END IF
  146.     END
  147.  
  148. SysopClose:
  149.  
  150.     CLS
  151.     Temp$ = "Loss of Carrier has been detected."
  152.     PRINT Temp$
  153.     GOTO RestoreInt
  154.  
  155.     'Keyboard input scan. Fetches characters from the remote keyboard.
  156.     'Echo's characters as enetered. Returns on carriage return.
  157.  
  158. KeyboardInput:
  159.  
  160.     A$ = ""
  161.     InCount = 0
  162.     ClearInputBuffer
  163.     DO
  164.         DO
  165.             Hit$ = INKEY$
  166.             IF Hit$ <> "" THEN EXIT DO
  167.         LOOP UNTIL DataWaiting
  168.         I$ = ""
  169.         IF Hit$ = "" THEN
  170.             DO WHILE DataWaiting
  171.                 I$ = I$ + CHR$(ReadChar)
  172.             LOOP
  173.         ELSE
  174.             I$ = Hit$
  175.         END IF
  176.         TookIn = LEN(I$)
  177.         IF I$ = CHR$(8) THEN
  178.             IF InCount THEN
  179.                 ' Your code to handle Backspace key ********
  180.                 ' Dont forget to send the Backspace sequence out to the
  181.                 ' Com port also with Transmit
  182.             END IF
  183.         END IF
  184.         IF I$ = CHR$(13) THEN EXIT DO
  185.         I$ = UCASE$(I$)
  186.         IF I$ > CHR$(&H1F) AND I$ < CHR$(&H7F) THEN
  187.             Transmit I$
  188.             PRINT I$;   ' You may need to echo in a different way *******
  189.             A$ = A$ + I$
  190.             InCount = InCount + TookIn
  191.         END IF
  192.     LOOP
  193.     RETURN
  194.  
  195.